package holdtime.xlxc.activities.main;

import android.content.Intent;
import android.os.Bundle;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import holdtime.xlxc.R;
import holdtime.xlxc.activities.practicedriving.IsConnected;
import holdtime.xlxc.activities.practicedriving.PracticeDrivingActivity;
import holdtime.xlxc.activities.practicedriving.PracticeDrivingMenuActivity;
import holdtime.xlxc.base.BaseActivity;
import holdtime.xlxc.tools.util.SharedPreferencesUtil;
import holdtime.xlxc.tools.util.ToastUtil;

public class NumActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        homeAsUpEnabled = true;
        actionBarTitle = "身份证号";
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_num);

        final EditText addET = (EditText) findViewById(R.id.add_et);
        String add = (String) SharedPreferencesUtil.get(this, "add", "");
        if (!TextUtils.isEmpty(add)) {
            addET.setText(add);
        } else {
            addET.setText("");
        }

        final EditText editText = (EditText) findViewById(R.id.jishi_et);
        String num = (String) SharedPreferencesUtil.get(this, "num", "");
        if (!TextUtils.isEmpty(num)) {
            editText.setText(num);
        }

        Button button = (Button) findViewById(R.id.jishi);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (editText.getText().toString().equals("") || addET.getText().toString().equals("")) {
                    ToastUtil.showToast(NumActivity.this, "请补全信息");
                } else {
                    SharedPreferencesUtil.put(NumActivity.this, "num", editText.getText().toString());
                    SharedPreferencesUtil.put(NumActivity.this, "add", addET.getText().toString());
                    SystemClock.sleep(1000);
                    if (IsConnected.getCurrent().isHasConnected()) {//正在连接，直接进入练车页面
                        Log.e(TAG, "单例connect 已连接");
                        startActivity(new Intent(NumActivity.this, PracticeDrivingActivity.class));
                    } else {
                        startActivity(new Intent(NumActivity.this, PracticeDrivingMenuActivity.class));
                        finish();
                    }
                }
            }
        });
    }
}
